<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, user-scalable=false"
    />
    <title>透明单例模式</title>
  </head>
  <body></body>
  <script>
    var CreateDiv = (function () {
      var instance;
      var CreateDiv = function (html) {
        if (instance) {
          return instance;
        }
        this.html = html;
        this.init();
        return (instance = this);
      };
      CreateDiv.prototype.init = function () {
        var div = document.createElement("div");
        div.innerHTML = this.html;
        document.body.appendChild(div);
      };
      return CreateDiv;
    })();
    var a = new CreateDiv("呵呵");
    var b = new CreateDiv("嘻嘻");
    console.log(a === b);
  </script>
</html>
